package dingding.使用线程;

public class Demo2 {

    public static void doSomethingA(){
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("-----doSomethingA");
    }

    public static void doSomethingB(){
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("-----doSomethingB");
    }

    public static void main(String[] args) throws InterruptedException {
        Long start = System.currentTimeMillis();

        Thread t = new Thread(() -> {
            doSomethingA();
        });
        t.start();

        doSomethingB();
        //使主线程进入等待池，线程t结束后被唤醒
        t.join();
        Long end = System.currentTimeMillis();

        System.out.println(end - start);
    }
}
